package cn.jbooter.coder.util;


public class JdbcUtil {

	/**
	 * 获得数据库驱动
	 * @param url
	 * @return
	 */
	public static String getDriverClassName(String url) {
		if (url == null || url.trim().length() == 0) {
			throw new RuntimeException("empty jdbc url !");
		}
		// 解析jdbc驱动
		if (url.trim().startsWith("jdbc:mysql:")) {
			return "com.mysql.jdbc.Driver";
		} else if (url.trim().startsWith("jdbc:oracle:") || url.trim().startsWith("JDBC:oracle:")) {
			return "oracle.jdbc.OracleDriver";
		} else {
			throw new RuntimeException("unkow jdbc driver : " + url);
		}
	}
	
	/**
	 * 获得数据库类型
	 * @param url
	 * @return
	 */
	public static String getDbType(String url) {
		if (url == null || url.trim().length() == 0) {
			throw new RuntimeException("empty jdbc url !");
		}
		// 解析jdbc驱动
		if (url.trim().startsWith("jdbc:mysql:")) {
			return "mysql";
		} else if (url.trim().startsWith("jdbc:oracle:") || url.trim().startsWith("JDBC:oracle:")) {
			return "oracle";
		} else {
			throw new RuntimeException("unkow db-type : " + url);
		}
	}

}
